package net.taiqin.tqerp.controller.fnd;

import net.taiqin.tqerp.controller.param.fnd.UserInfoParam;
import net.taiqin.tqerp.domain.fnd.FndUserVO;
import net.taiqin.tqerp.exception.MyException;
import net.taiqin.tqerp.service.fnd.IFndUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/fndUser"})
public class FndUserController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    public IFndUserService fndUserService;

    @RequestMapping(
            value = {"/getUserInfo"},
            method = {RequestMethod.POST}
    )
    public FndUserVO getUserInfo(@RequestBody UserInfoParam userInfo) {
        this.logger.info("---------------------------------获取用户信息-----------------------");
        FndUserVO fndUserVO = this.fndUserService.findFndUser(userInfo);
        return fndUserVO;
    }

    @RequestMapping(
            value = {"/getUserInfo2"},
            method = {RequestMethod.GET}
    )
    public FndUserVO getUserInfo(@RequestParam("loginName") String loginName, @RequestParam("password") String password, @RequestParam("tenantId") String tenantId) {
        this.logger.info("---------------------------------获取用户信息-----------------------");
        UserInfoParam userInfo = new UserInfoParam();
        userInfo.setLoginName(loginName);
        userInfo.setPassword(password);
        userInfo.setTenantId(tenantId);
        FndUserVO fndUserVO = this.fndUserService.findFndUser(userInfo);
        return fndUserVO;
    }

    @RequestMapping({"/json"})
    public String json() throws MyException {
        throw new MyException("发生错误2");
    }

    @RequestMapping({"/json1"})
    public String json1() throws MyException {
        throw new MyException("发生错误1");
    }
}
